package org.jsola.hr.helper;

import org.jsola.hr.dto.CrmMemberRelationAddDTO;
import org.jsola.hr.dto.CrmMemberRelationUpdateDTO;
import org.jsola.hr.entity.CrmMemberRelationDO;
import org.jsola.hr.query.CrmMemberRelationQuery;
import org.jsola.hr.service.ICrmMemberRelationService;
import org.jsola.hr.vo.CrmMemberRelationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 成员关系表
 *
 * @author zhr
 */
@Component
public class CrmMemberRelationTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmMemberRelationService crmMemberRelationService;

    /**
     * 生成add测试数据
     * @return CrmMemberRelationAddDTO
     */
    public CrmMemberRelationAddDTO getCrmMemberRelationAddDTO(){
        CrmMemberRelationAddDTO crmMemberRelationAddDTO = new CrmMemberRelationAddDTO();
        crmMemberRelationAddDTO.setMemerId(getRandomValue("varchar",32));
        crmMemberRelationAddDTO.setSuperiorMemberId(getRandomValue("varchar",32));
        return crmMemberRelationAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmMemberRelationUpdateDTO
     */
    public CrmMemberRelationUpdateDTO getCrmMemberRelationUpdateDTO(CrmMemberRelationVO crmMemberRelationVO){
        return crmMemberRelationService.selectDOById(crmMemberRelationVO.getId(), SITE_ID).to(CrmMemberRelationUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmMemberRelationQuery
     */
    public CrmMemberRelationQuery getCrmMemberRelationQuery() {
        CrmMemberRelationQuery crmMemberRelationQuery = new CrmMemberRelationQuery();
        List<CrmMemberRelationDO> crmMemberRelationDOList = crmMemberRelationService.list(new CrmMemberRelationDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmMemberRelationDOList)) {
            CrmMemberRelationDO crmMemberRelationDO = crmMemberRelationDOList.get(0);
            crmMemberRelationQuery = crmMemberRelationDO.to(CrmMemberRelationQuery.class);
        }
        return crmMemberRelationQuery;
    }

    /**
     * 保存示例
     * @return CrmMemberRelationVO
     */
    public CrmMemberRelationVO saveCrmMemberRelationExample(){
        CrmMemberRelationAddDTO addDTO = this.getCrmMemberRelationAddDTO();
        CrmMemberRelationVO crmMemberRelationVO = crmMemberRelationService.save(addDTO,buildTokenUser());
        return crmMemberRelationVO;
    }


}

